Skip to content

WhitelistValidator

Sub classes

Name Children Inherits
EmptyValidator
prettyqt.validators.whitelistvalidator

    Base classes

    Name Children Inherits
    Validator
    prettyqt.gui.validator

    ⋔ Inheritance diagram

    graph TD
      3611351787["validators.WhitelistValidator"]
      422589614["gui.Validator"]
      1804432572["gui.ValidatorMixin"]
      3227531497["core.ObjectMixin"]
      2751680898["builtins.object"]
      49520861["QtGui.QValidator"]
      3984060476["QtCore.QObject"]
      37984305["Shiboken.Object"]
      422589614 --> 3611351787
      1804432572 --> 422589614
      3227531497 --> 1804432572
      2751680898 --> 3227531497
      49520861 --> 422589614
      3984060476 --> 49520861
      37984305 --> 3984060476
      2751680898 --> 37984305

    🛈 DocStrings

    Bases: Validator

    Validator which allows a fixed list of strings.

    Source code in prettyqt/validators/whitelistvalidator.py
    class WhitelistValidator(gui.Validator):
        """Validator which allows a fixed list of strings."""
    
        ID = "whitelist"
    
        def __init__(
            self,
            options: list[str] | None = None,
            parent: QtCore.QObject | None = None,
        ):
            super().__init__(parent)
            self._options = options or []
    
        def __eq__(self, other: object):
            return isinstance(other, WhitelistValidator) and self._options == other._options
    
        def validate(self, text: str, pos: int = 0):
            if any(option == text for option in self._options):
                return self.State.Acceptable, text, pos
            if any(option.startswith(text) for option in self._options):
                return self.State.Intermediate, text, pos
            return self.State.Invalid, text, pos
    

    :fa-brands-github: Show source on GitHub